/*
 * utils.h
 *
 *  Created on: Jul 1, 2024
 *      Author: PIANO
 */

#ifndef COMPONENTS_UTILS_H_
#define COMPONENTS_UTILS_H_

/**
 * includes
 *
 */
#include "main.h"
#include <stdint.h>
#include <stdbool.h>

/**
 * functions
 *
 */
int32_t tickDelta(__IO uint32_t *lastTick);
void digitalFilter(bool *output, bool input, uint32_t filterTimeSet,
		uint32_t *timeCount);
bool isPosedge(bool in, bool *lastIn);
bool isNegedge(bool in, bool *lastIn);

uint16_t toUint16(uint8_t *bytes);
int16_t toInt16(uint8_t *bytes);
uint32_t toUint32(uint8_t *bytes);
int32_t toInt32(uint8_t *bytes);
float u16ToFloat(uint16_t *pSrc);
void toBytes2(uint8_t *bytes, uint16_t word);
void toBytes4(uint8_t *bytes, uint32_t dword);

void int8Limit(int8_t *value, int8_t min, int8_t max);
void uint8Limit(uint8_t *value, uint8_t min, uint8_t max);
void int16Limit(int16_t *value, int16_t min, int16_t max);
void uint16Limit(uint16_t *value, uint16_t min, uint16_t max);

#endif /* __UTILS_H_ */
